/*
 * table_TypeSpecifier.c
 *
 *  Created on: 2012/03/29
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"
#include "../../parser/cc/cc.h"
typedef struct _TYPESPECIFIER_TAG
{
	UCHAR			ucVolatile;	/* 2 */
	UCHAR			ucConst;		/* 3 */
	UCHAR			ucRestrict;	/* 2 */
	UCHAR			ucExtern;		/* 4 */

	UCHAR			ucStatic;		/* 5 */
	UCHAR			ucAuto;		/* 6 */
	UCHAR			ucTypedef;	/* 7 */
	UCHAR			ucRegister;	/* 8 */

	UCHAR			ucInterrupt;	/* 9 */
	UCHAR			ucInline;		/* 10 */
	UCHAR			ucAsm;		/* 11 */
	UCHAR			ucNear;

	UCHAR			ucFar;
	UCHAR			usKind;		/* 12 */
	union{
		UCHAR		ucTypeKey[4]; /* short long  signed unsigned */
		AST			astMemberDeclaration;
	}unParam;							/* 13 */
	AST			astSymDefInfo;	/* 14 */
	AST			astTypeInfo;		/* 15 */
	AST			astDeclaration;	/* 16 */
	AST			astLocation;		/* 17 */
} TYPESPECIFIER, *PTYPESPECIFIER;

#define TableSize  (sizeof(TYPESPECIFIER ))
#define TableType  PTYPESPECIFIER
#define stTable stTypeSpecifierManager.memoryBlocks
#define maxTable stTypeSpecifierManager.maxRecordNum
#define  maxNumPerBlk  (stTypeSpecifierManager.astMaxNum_Block)

static TABLEMANAGER stTypeSpecifierManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stTypeSpecifierManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stTypeSpecifierManager, resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}


static BOOL ClearTable( VOID )
{
	return Clear_Com( &stTypeSpecifierManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stTypeSpecifierManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stTypeSpecifierManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID )
{
	return maxTable;
}
//		ACCESS_U2_FIELD  restrictNum;
static U2 getRestrictNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucRestrict;
}
static U2 setRestrictNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucRestrict = value;
}
//		ACCESS_U2_FIELD  volatileNum;
static U2 getVolatileNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucVolatile;
}
static U2 setVolatileNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucVolatile = value;
}
//		ACCESS_U2_FIELD  constNum;
static U2 getConstNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucConst;
}
static U2 setConstNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucConst = value;
}
//		ACCESS_U2_FIELD  externNum;
static U2 getExternNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucExtern;
}
static U2 setExternNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucExtern = value;
}
//		ACCESS_U2_FIELD  staticNum;
static U2 getStaticNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucStatic;
}
static U2 setStaticNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucStatic = value;
}
//		ACCESS_U2_FIELD  autoNum;
static U2 getAutoNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucAuto;
}
static U2 setAutoNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucAuto = value;
}
//		ACCESS_U2_FIELD  typedefNum;
static U2 getTypeDefNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucTypedef;
}
static U2 setTypeDefNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucTypedef = value;
}
//		ACCESS_U2_FIELD  registerNum;
static U2 getRegisterNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucRegister;
}
static U2 setRegisterNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucRegister = value;
}
//		ACCESS_U2_FIELD  interruptNum;
static U2 getInterruptNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucInterrupt;
}
static U2 setInterruptNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucInterrupt = value;
}
//		ACCESS_U2_FIELD  inlineNum;
static U2 getInlineNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucInline;
}
static U2 setInlineNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucInline = value;
}
//		ACCESS_U2_FIELD  asmNum;
static U2 getAsm( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucAsm;
}
static U2 setAsm( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucAsm = value;
}
//		ACCESS_U2_FIELD  nearNum;
static U2 getNear( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucNear;
}
static U2 setNear( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucNear = value;
}
//		ACCESS_U2_FIELD  farNum;
static U2 getFar( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucFar;
}
static U2 setFar( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ucFar = value;
}
//		ACCESS_U2_FIELD  specifyKind;
static U2 getKind( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usKind;
}
static U2 setKind( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usKind = value;
}
//		ACCESS_U2_FIELD  signNum;
static U2 getSignNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != TYPEDEF_BASE ){
		return 0;
	}
	return pTbl->unParam.ucTypeKey[0];
}
static U2 setSignNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != 0 && pTbl->usKind != TYPEDEF_BASE ){
		Throw_MemoryError( &stTypeSpecifierManager, DATA_SETTING_MISS, astIndex, pTbl->usKind );
	}
	pTbl->usKind = TYPEDEF_BASE;
	return pTbl->unParam.ucTypeKey[0] = value;
}
//		ACCESS_U2_FIELD  unsigneNum;
static U2 getUnSignNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != TYPEDEF_BASE ){
		return 0;
	}
	return pTbl->unParam.ucTypeKey[1];
}
static U2 setUnSignNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != 0 && pTbl->usKind != TYPEDEF_BASE ){
		Throw_MemoryError( &stTypeSpecifierManager, DATA_SETTING_MISS, astIndex, pTbl->usKind );
	}
	pTbl->usKind = TYPEDEF_BASE;
	return pTbl->unParam.ucTypeKey[1] = value;
}
//		ACCESS_U2_FIELD  longNum;
static U2 getLongNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != TYPEDEF_BASE ){
		return 0;
	}
	return pTbl->unParam.ucTypeKey[2];
}
static U2 setLongNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != 0 && pTbl->usKind != TYPEDEF_BASE ){
		Throw_MemoryError( &stTypeSpecifierManager, DATA_SETTING_MISS, astIndex, pTbl->usKind );
	}
	pTbl->usKind = TYPEDEF_BASE;
	return pTbl->unParam.ucTypeKey[2] = value;
}
//		ACCESS_U2_FIELD  shortNum;
static U2 getShortNum( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != TYPEDEF_BASE ){
		return 0;
	}
	return pTbl->unParam.ucTypeKey[3];
}
static U2 setShortNum( AST astIndex, U2 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != 0 && pTbl->usKind != TYPEDEF_BASE ){
		Throw_MemoryError( &stTypeSpecifierManager, DATA_SETTING_MISS, astIndex, pTbl->usKind );
	}
	pTbl->usKind = TYPEDEF_BASE;
	return pTbl->unParam.ucTypeKey[3] = value;
}
//		ACCESS_IDX_FIELD memberChain;
static AST getMemberChain( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != TYPEDEF_UNION
		&&  pTbl->usKind != TYPEDEF_STRUCT
		&&  pTbl->usKind != TYPEDEF_ENUM ){
		return 0;
	}
	return pTbl->unParam.astMemberDeclaration;
}
static AST setMemberChain( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	if( pTbl->usKind != TYPEDEF_UNION
		&&  pTbl->usKind != TYPEDEF_STRUCT
		&&  pTbl->usKind != TYPEDEF_ENUM
		&&  pTbl->usKind != 0 ){
		Throw_MemoryError( &stTypeSpecifierManager, DATA_SETTING_MISS, index, pTbl->usKind );
	}
	return pTbl->unParam.astMemberDeclaration=value;
}
//		ACCESS_IDX_FIELD symbol;
static AST getSymbol( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astSymDefInfo;
}
static AST setSymbol( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astSymDefInfo=value;
}
//		ACCESS_IDX_FIELD typeinfo;
static AST getType( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astTypeInfo;
}
static AST setType( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astTypeInfo=value;
}
//		ACCESS_IDX_FIELD declaration;
static AST getDeclaration( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astDeclaration;
}
static AST setDeclaration( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astDeclaration=value;
}
//		ACCESS_IDX_FIELD codeScp;
static AST getCodeScp( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLocation;
}
static AST setCodeScp( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLocation=value;
}
const TYPESPECIFIERACCESS stTypeSpecifierAccess = {
//		BOOL (*clear)( VOID );
		ClearTable,
//		BOOL (*reset)( VOID );
		ResetTable,
//		BOOL (*alloc)( AST );
		AllocTable,
//		AST  (*getMax)( VOID );
		getMaxLineNum,
		//		ACCESS_U2_FIELD  restrictNum;
		{
				getRestrictNum,
				setRestrictNum
		},
		//		ACCESS_U2_FIELD  volatileNum;
		{
				getVolatileNum,
				setVolatileNum
		},
		//		ACCESS_U2_FIELD  constNum;
		{
				getConstNum,
				setConstNum
		},
		//		ACCESS_U2_FIELD  externNum;
		{
				getExternNum,
				setExternNum
		},
		//		ACCESS_U2_FIELD  staticNum;
		{
				getStaticNum,
				setStaticNum
		},
		//		ACCESS_U2_FIELD  autoNum;
		{
				getAutoNum,
				setAutoNum
		},
		//		ACCESS_U2_FIELD  typedefNum;
		{
				getTypeDefNum,
				setTypeDefNum
		},
		//		ACCESS_U2_FIELD  registerNum;
		{
				getRegisterNum,
				setRegisterNum
		},
		//		ACCESS_U2_FIELD  interruptNum;
		{
				getInterruptNum,
				setInterruptNum
		},
		//		ACCESS_U2_FIELD  inlineNum;
		{
				getInlineNum,
				setInlineNum
		},
		//		ACCESS_U2_FIELD  asmNum;
		{
				getAsm,
				setAsm
		},
		//		ACCESS_U2_FIELD  nearNum;
		{
				getNear,
				setNear
		},
		//		ACCESS_U2_FIELD  farNum;
		{
				getFar,
				setFar
		},
		//		ACCESS_U2_FIELD  specifyKind;
		{
				getKind,
				setKind
		},
		//		ACCESS_U2_FIELD  signNum;
		{
				getSignNum,
				setSignNum
		},
		//		ACCESS_U2_FIELD  unsigneNum;
		{
				getUnSignNum,
				setUnSignNum
		},
		//		ACCESS_U2_FIELD  longNum;
		{
				getLongNum,
				setLongNum
		},
		//		ACCESS_U2_FIELD  shortNum;
		{
				getShortNum,
				setShortNum
		},
		//		ACCESS_IDX_FIELD memberChain;
		{
				getMemberChain,
				setMemberChain
		},
		//		ACCESS_IDX_FIELD symbol;
		{
				getSymbol,
				setSymbol
		},
		//		ACCESS_IDX_FIELD typeinfo;
		{
				getType,
				setType
		},
		//		ACCESS_IDX_FIELD declaration;
		{
				getDeclaration,
				setDeclaration
		},
		//		ACCESS_IDX_FIELD codeScp;
		{
				getCodeScp,
				setCodeScp
		}
};
/* end of file */

